package com.skt.common_hr.msstop.model
{
	import com.skt.common_hr.common.approval.IRequestApprovalProxy;
	import com.skt.common_hr.common.puremvc.CommonProxy;
	import com.wcl.utils.DateUtil;

	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;

	import mx.collections.ArrayCollection;

	public class MsstopApprovalProxy extends CommonProxy implements IRequestApprovalProxy
	{
		public static const NAME:String = "MsstopApprovalProxy";
		public var dataProvider:ArrayCollection;

		private var _bAppType:Boolean = false;		// 정산 포함여부
		private var _amount:Number;

		public var esstopObj:Object;

		private var templateHTML1:String = "";
		/**
		 * 생성자
		 *
		 * @param
		 * @return void
		 */
		public function MsstopApprovalProxy(data:Object=null)
		{
			super(NAME, data);
			loadTemplate1();
		}

		private var _key:String = "";
		public function get key():String
		{
			return _key;
		}
		public function set key(k:String):void
		{
			_key = k;
		}

		public function get title():String
		{
			var tmp:String;
			tmp = "Top Bank 신청";
//			tmp = "구성원 포상 (";
//			tmp += esstopObj.AWDDT + ", " + esstopObj.ENAME;
//			tmp += ")";
			return tmp;
		}



		public function get content():String
		{
			return buildHTML();
		}

		public function get appCode():String
		{
			return "14"; 	//
		}

 		private function loadTemplate1():void
		{
			var loader:URLLoader = new URLLoader();
			var request:URLRequest = new URLRequest("assets/template/esstop.tmp");
			loader.addEventListener(Event.COMPLETE, templateResult);
			loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);

            try {
                loader.load(request);
            } catch (error:Error) {
                trace("Unable to load requested document.");
            }
		}


		private function templateResult(event:Event):void
		{
			templateHTML1 = event.target.data;
		}



		private function ioErrorHandler(event:IOErrorEvent):void
		{
			trace("ioErrorHandler: " + event);
		}


		private function buildHTML():String
		{
			var htmlAll:String = templateHTML1;
			var htmlBlock:String = "";

			var ptnENAME:RegExp  		= /__ENAME__/;
			var ptnSDATE:RegExp  		= /__SDATE__/;
			var ptnKIND:RegExp  		= /__KIND__/;
			var ptnBETRG:RegExp  		= /__BETRG__/;
			var ptnBUSET:RegExp  		= /__BUSET__/;
			var ptnBREAS:RegExp  		= /__BREAS__/;

			htmlAll = htmlAll.replace(ptnENAME		, esstopObj.ENAME);
			htmlAll = htmlAll.replace(ptnSDATE		, esstopObj.SDATE_TX);
			htmlAll = htmlAll.replace(ptnKIND		, esstopObj.KIND);
			htmlAll = htmlAll.replace(ptnBETRG		, esstopObj.BETRG);
			htmlAll = htmlAll.replace(ptnBUSET		, esstopObj.BUSET);
			htmlAll = htmlAll.replace(ptnBREAS		, esstopObj.BREAS);

			return htmlAll;
		}
	}
}